<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>处方附加费</title>
		<link rel="stylesheet" type="text/css" href="js/bootstarp-3.3.7/css/bootstrap.min.css"/>
		<script src="vendor/jquery/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
	<script>
			$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
				$.ajaxSetup({
					crossDomain: true,
					xhrFields: {
						withCredentials: true
					}
				});
			});
		</script>
	<script type="text/javascript">
		
		$(function() {
		
				$("table").bootstrapTable({
					url: "http://127.0.0.1:8099/DzmHisPrescriptionExtrachargeall",
					pagination: true,
					pageSize: 10,
					queryParams: queryParams,
					columns: [{
						field: 'pre_id',
						title: '序号',
						align: 'center',
					}, {
						field: 'extracharges_name',
						title: '费用名称',
						align: 'center',
					}, {
						field: 'fee',
						title: '金额',
						align: 'center',
					}, {
						field: 'typename',
						title: '处方类型',
						align: 'center',
					}, {
						title: '修改',
						align: 'center',
						formatter: function(value, row, index) {
							return '<button onclick="delet(' + row.pre_id + ')" class="btn btn-danger glyphicon glyphicon-trash"></button>  <button onclick="upda(' + row.pre_id + ')" class="btn btn-info glyphicon glyphicon-edit"></button>'
						}
					}]

				})
})
	/**
	 * 下拉框赋值
	 */
//		$.getJSON("http://127.0.0.1:8099/typeall", function(data) {			
//			for(var i = 0; i < data.length; i++) {				
//				if (data[i].type==true) {
//					$("#type,#type3").append("<option value='" + data[i].type + "'>西药处方</option>")
//				}
//				if (data[i].type==false) {
//					$("#type,#type3").append("<option value='" + data[i].type + "'>中药处方</option>")
//				}
//			
//			}
//		})
		
		
		/**
		 * 删除
		 * @param {Object} pre_Id
		 */
		function delet(pre_Id) {
		$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/Prescription_surchargedele",
				data: "pre_Id=" + pre_Id,
				success: function(data) {
					alert("删除成功")
					$("table").bootstrapTable('refresh')
				}
			});
			
			
		}
		
		/**
		 * 添加
		 */
		function add () {
			if($("#extracharges_name").val().trim().length==0||$("#fee").val().trim().length==0||$("#type").val().trim().length==""){
				alert("请把信息填写完整")
			}else{
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/Prescription_surchargeinsert",
				data:$("#for").serialize(),
				success: function(data) {
					$("#myModal").modal("hide")
					$("table").bootstrapTable('refresh')						
							}
			});
			}
		}
		
		/**
		 * 修改查询
		 * @param {Object} pre_id
		 */
		function upda (pre_id) {
			$("#myModal2").modal("show")
				$.ajax({
					type: "post",
					url: "http://127.0.0.1:8099/DzmHisPrescriptionExtrachargeidall",
					data: "pre_id=" + pre_id,  				
					success: function(data) {
						$("#pre_id").val(data[0].pre_id);
						$("#extracharges_name3").val(data[0].extracharges_name);
						$("#fee3").val(data[0].fee);
						$("#type3").val(data[0].type);
					}
				});
		}
		
		/**
		 * 修改
		 */
		function up () {			
			if($("#extracharges_name3").val().trim().length==0||$("#fee3").val().trim().length==0||$("#type3").val().trim().length==""){
				alert("请把信息填写完整")
			}else{
			$.ajax({
					type: "post",
					url: "http://127.0.0.1:8099/DzmHisPrescriptionExtrachargeup",
					data:$("#for3").serialize(),
					success: function(data) {
						$("#myModal2").modal("hide")
						$("table").bootstrapTable('refresh')
					}
				});
			}
		}
		
		
	
		function btn2() {
				$("#extracharges_name").val("");
				$("#fee").val("");
				$("#type").val("");
				$("#myModal").modal("show");
			}
		
		function queryParams(Params) {
			return {
				'extracharges_name': $("#extracharges_name2").val(),
			}
		}
		function select() {
			$("table").bootstrapTable('refresh')
		}
		
	</script>

	</head>
	<body>
		<div align="center">
			<form class="form-inline">
				<br />
				<div class="form-group">
					<label for="exampleInputEmail2">费用名称查询：</label>
					<input type="text" class="form-control" id="extracharges_name2" name="extracharges_name" placeholder="请输入费用名称查询">
				
					<button type="button" class="btn btn-default glyphicon glyphicon-search" onclick="select()"></button>
					<button type="button" class="btn btn-primary glyphicon glyphicon-plus"  onclick="btn2()"></button>
				</div>
			</form>
		</div>
		<br />
		
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">添加新处方附加费用</h4>
					</div>
					<div class="modal-body">


					<form class="form-horizontal" id="for">
					 <div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">费用名称：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="extracharges_name" name="extracharges_name" placeholder="费用名称">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">费用金额：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="fee" name="fee" placeholder="费用金额">
    							</div>
  					</div>

  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">处方类型：</label>
   								 <div class="col-sm-8">
									<select class="form-control" id="type" name="type">
										<option value="">请选择处方类型</option>
										<option value="0">中药处方</option>
										<option value="1">西药处方</option>
									</select>    							
   								 </div>
  					</div>
						

						</form>
						
						
					
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal" onclick="close()"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok"  onclick="add()"></button>
					</div>
				</div>
			</div>
		</div>
		
		
		
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">修改处方</h4>
					</div>
					<div class="modal-body">


					<form class="form-horizontal" id="for3">
					 <div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">费用名称：</label>
   								 <div class="col-sm-8">
   								 	<input type="hidden"id="pre_id" name="pre_id" />
     								 <input type="text" class="form-control" id="extracharges_name3" name="extracharges_name"  placeholder="费用名称">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">费用金额：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="fee3" name="fee" placeholder="费用金额">
    							</div>
  					</div>

  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">处方类型：</label>
   								 <div class="col-sm-8">
									<select class="form-control" id="type3" name="type">
										<option value="">请选择处方类型</option>
										<option value="0">中药处方</option>
										<option value="1">西药处方</option>
									</select>    							
   								 </div>
  					</div>
						

						</form>
						
						
					
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal" onclick="close()"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok"  onclick="up()"></button>
					</div>
				</div>
			</div>
		</div>
		<table class="table table-striped" >		
		</table>	
	</body>
</html>
